import userAgreementPopup from '@/components/user-agreement-popup/user-agreement-popup.vue' //免责
import md5 from '@/utils/blueimp-md5.js'
export default {
  components: {
    userAgreementPopup, //弹出框组件
  },
  data() {
    return {
      mobileName: '', //输入的手机号
      namePhone: '', //输入的手机号
      invitationCode: '', //输入的验证码
      type: 'text', //input输入格式
      Yqtype: 'text', //邀请码input输入格式
      showPopup: false, //弹框显隐
      isAgree: false, //false未选择  true我同意选择
      olduser: false, //false为新用户 默认新用户，true为老用户
      yqsuccess: false, //邀请成功
      yqfail: false, //邀请失败
      deletebtn: true, //邀请码清楚按钮
      nextStepstat: false, //false下一步灰色，true下一步点亮
      passwordSMSLogin: '密码登录', //密码短信登录切换
      pasworcontrol: false, //密码登录控制

      passwordPlaceholder: '请输入密码', //input默认提示
      showpasswordPlaceholder: false, //密码小标题
      showPasswordClearIcon: false, //密码小叉叉
      showPassword: true, //隐藏显示密码
      Password: '', //input输入的值
      eye: 'eye-off', //显示隐藏的眼睛图标
      isFocus: false,

      guidePages: false, //隐藏显示登录
      historyInfo: null, //历史手机号

      scrollTop: 0,
      old: {
        scrollTop: 0
      },
      imeis: '',
      weixlogin: true,
      weixnumber: 0, //唤起微信登录次数
      platform: '',
      sweixin: '',
      wxcode: '',//微信登录使用的code
    }
  },
  computed: {
    isDisabled() {
      if (this.mobileName.length === 11) {
        return false
      }
      return true
    },
    btnText() {
      if (this.quickUser && this.mobileName === this.quickUser) {
        return '下一步'
      }
      return '获取验证码'
    },
  },
  onLoad(e) {
    const _this = this
    this.loadExecution() //调用登录页

    let pages = getCurrentPages()
    let current = null
    let num = 1
    pages.map((item, index) => {
      if (item.route === 'pages_logins/login/login') {
        num = pages.length - index
        current = pages[pages.length - index]
      }
    })
    if (current) {
      getApp().globalData.redirect = current.route + this.$u.queryParams(current.options)
    }

    // 缓存中取到的好友邀请码
    let codes = uni.getStorageSync('invitationcode')
    if (codes) {
      console.log(codes)
      this.invitationCode = codes
      this.olduser = false
    }

    // #ifdef APP-PLUS
    //获取历史登录记录-imei
    plus.share.getServices(s => {
      var shares = {}
      for (var i = 0; i < s.length; i++) {
        var t = s[i]
        shares[t.id] = t
        if (shares[t.id].id === 'weixin') {
          _this.sweixin = shares['weixin']
        }
      }
    }, function(e) {
      console.log('获取分享服务列表失败：' + e.message)
    })
    plus.device.getInfo({
      success: function(res) {
        //因为ios没有imei,所以取uuid
        const imei = res.imei.length < 2 ? res.uuid : res.imei
        _this.$store.commit('setImei', imei)
        _this.verifyMobile(imei)
        // console.log('获取到得imei',imei)
      },
      complete: function(err) {},
    })
    // #endif

    //测试位置
    // this.verifyMobile()
    // this.$store.commit('setImei', '861751030102251,861751030102244')
    // var i = this.$store.state.imei

    // 使用这个方法只需要this.$store.commit('方法名',要传入的变量)
    // 使用state中的值只需要this.$store.state.变量名

    if (e.number) {
      this.mobileName = e.number
      this.showClearIcon = true
      this.showSmalltitle()
    }
    // 获取设备信息
    const systemInfo = uni.getSystemInfoSync()
    console.log(systemInfo)
    let plat = ''
    // #ifdef APP-PLUS
    plat = '_APP'
    //  #endif
    // #ifdef H5
    plat = '_H5'
    //  #endif
    // #ifdef MP-WEIXIN
    plat = '_WEIXIN'
    //  #endif
    this.platform = systemInfo.platform
    if (systemInfo.brand) {
      this.platform = this.platform + '_' + systemInfo.brand
    }
    if (systemInfo.model) {
      this.platform = this.platform + '_' + systemInfo.model
    }
    this.platform = this.platform + plat

  },
  onShow() {
    // #ifdef MP-WEIXIN
    let _this=this
    wx.login({
      success(codee) {
        _this.wxcode=codee.code
      }
    })
    //  #endif
    // #ifdef APP-PLUS
    if (plus.os.name !== 'Android') {
      this.weixlogin = false
    } else {
      this.weixlogin = true
    }
    //使用小程序登录模块---------获取用户信息到清除用户信息
    //有传过来参数就进入判断
    // if(plus.runtime.arguments){
    //   let wxarguments =JSON.stringify(plus.runtime.arguments)
    //   //判断是否为取消登录，取消直接返回上一页
    //   if(wxarguments.cancel){
    //     uni.navigateBack({delta: 1})
    //   }
    //   //判断是否返回了用户的token,返回进行数据处理
    //   if(wxarguments.token){
    //     console.log('plus.runtime.arguments-------------------------------')
    //     console.log(wxarguments)
    //   }
    //   setTimeout(() => {
    //     plus.runtime.arguments = null
    //     plus.runtime.arguments = ''
    //     console.log(plus.runtime.arguments)
    //   },1000)
    // }
    // #endif
  },
  //监听默认返回事件
  // onBackPress(e) {
  //   return true
  // },
  methods: {
    md5,
    // #ifdef MP-WEIXIN
    // 小程序登录
    decryptPhoneNumber(e) {
      let _this=this
      _this.wxgologin(e)
    },

    async wxgologin(phone){
      let _this=this
      try {
        uni.showLoading({
          title: '登陆中...'
        })
        // 洗车站分享id
        let carWashStationShareId = uni.getStorageSync('carWashStationShareId') || ''
        // 商户id
        let bussinessid = uni.getStorageSync('bussinessid') || ''
        let busstrue = uni.getStorageSync('busstrue') || ''
        let reqObj = {
          inviteCode: _this.invitationCode, //商户id或邀请码
          imei: _this.$store.state.imei, //IMEI
          WxDecipherItem: {
            encrypdata: encodeURIComponent(phone.detail.encryptedData),
            ivdata: encodeURIComponent(phone.detail.iv),
            code: encodeURIComponent(_this.wxcode)
          },
          LoginType: 2, //微信小程序登录传2
          login_Platform: _this.platform, //设备平台信息-仅注册需要
        }
        // 商户端分享
        if (bussinessid) {
          reqObj.inviteCode = bussinessid
          reqObj.ShareType = 3
          // 后台管理系统洗车站分享
        } else if (carWashStationShareId) {
          reqObj.inviteCode = carWashStationShareId
          reqObj.ShareType = 4
        }
        console.log(JSON.stringify(reqObj))
        const res = await _this.$api.user.ClientLogin(reqObj)
        uni.hideLoading()
        _this.loginSuccess(res.data) //保存
        if (res.code === 200) {
          if (bussinessid || carWashStationShareId) {
            _this.purchaseinformation = uni.getStorageSync('purchaseinformation')
            if (_this.purchaseinformation !== '' && busstrue) {
              //true进入洗车券支付
              _this.AddSelfServiceCarWashDiscountOrder() //false没有发显示弹框，true已发放不显示
              return
            }
            uni.removeStorageSync('showmoButton')
            uni.removeStorageSync('bussinessid')
            uni.removeStorageSync('purchaseinformation')
            uni.removeStorageSync('carWashStationShareId')
          }

          const storeId = uni.getStorageSync('storeId')
          if (storeId) {
            uni.removeStorageSync('storeId')
            uni.reLaunch({
              url: '/pages_commodity/lineUp/lineUp?storeId=' + storeId
            })
            return
          }
          const existingOrder = uni.getStorageSync('existingOrder')
          if (existingOrder) {
            uni.removeStorageSync('existingOrder')
            uni.reLaunch({
              url: '/pages_commodity/selfWash/existingOrder?id=' + existingOrder
            })
            return
          }
          const signData = uni.getStorageSync('signData')
          if (signData && signData.id) {
            uni.removeStorageSync('signData')
            uni.reLaunch({
              url: `/pages_common/sign/sign?state=${signData.state}&id=${signData.id}`
            })
            return
          }
          let pages = getCurrentPages()
          if (pages.length <= 1) {
            uni.switchTab({
              url: '/pages/index/index'
            })
          } else {
            uni.navigateBack({
              delta: 1
            })
          }
          uni.setStorage({
            key: 'launchFlag',
            data: true,
          })
        }

      } catch (err) {
        uni.hideLoading()
        uni.reLaunch({
          url: '/pages_logins/login/login'
        })
        console.log('捕获错误', err)
      }
    },
    // #endif

    scroll: function(e) {
      this.old.scrollTop = e.detail.scrollTop
    },
    // 先看看,跳转到首页
    skipindex() {
      /**
       * 向本地存储中设置launchFlag的值，即启动标识；
       */
      uni.setStorage({
        key: 'launchFlag',
        data: true,
      })
      uni.switchTab({
        url: '/pages/index/index'
      })
      // uni.showTabBar()
    },
    loadExecution: function() {
      /**
       * 获取本地存储中launchFlag的值
       * 若存在，说明不是首次启动，直接进入首页；
       * 若不存在，说明是首次启动，进入引导页；
       */
      try {
        // 获取本地存储中launchFlag标识
        const value = uni.getStorageSync('launchFlag')
        if (value) {
          // launchFlag=true直接跳转到首页
          uni.switchTab({
            url: '/pages/index/index'
          })
        } else {
          // launchFlag!=true显示引导页
          this.guidePages = true
        }
      } catch (e) {
        // error
        uni.setStorage({
          key: 'launchFlag',
          data: true,
          success: function() {
            console.log('error时存储launchFlag')
          }
        })
        this.guidePages = true
      }
      return
      uni.switchTab({
        url: '/pages/index/index'
      })
    },
    //实时监控--手机号--input输入的值
    onInput(event) {
      this.namePhone = event
      this.$u.debounce(this.moblieInput, 100)
    },
    moblieInput() {
      let event = this.namePhone
      const data = event.replace(/[^\d.]/g, '')
      var phones = data.replace(/\s+/g, '')
      phones = phones.substring(0, 11)
      this.mobileName = phones
      if (phones.length > 7) {
        this.namePhone =
          phones.slice(0, 3) +
          ' ' +
          phones.slice(3, 7) +
          ' ' +
          phones.slice(7)
      } else if (phones.length > 3) {
        this.namePhone = phones.slice(0, 3) + ' ' + phones.slice(3)
      } else {
        this.namePhone = phones
      }
      // 手机号不足11位,邀请码不足6位
      if (phones.length < 11) {
        this.nextStepstat = false
        this.olduser = false //显示邀请码
        this.isAgree = false
      } else {
        this.nextStepstat = true
        this.isFocus = false
        console.log('this.mobileName', phones)
        this.CheckAccountExsist(phones)
      }
    },
    //实时监控--邀请码--input输入的值
    clearInput(event) {
      this.invitationCode = event //input输入的内容
    },
    // 当用户输入邀请码的时候会给出二次提示“请确保邀请码准确无误，注册登录以后将无法改变身份”
    invinputfocus() {
      this.$refs.uToast.show({
        title: '请确保邀请码准确无误 注册登录以后将无法改变身份',
        icon: false,
        type: 'warning',
        duration: 3000
      })
    },
    //开启关闭历史记录icon
    histricon() {
      this.isFocus = !this.isFocus
    },
    //当input框获取焦点的时候，显示小标题，隐藏默认提示文字
    showSmalltitle() {
      this.placeholder = '' //input默认提示字
      this.isFocus = true

      if (this.mobileName.length === 11) {
        this.isFocus = false
      }
    },
    //当input框失去焦点的时候，隐藏小标题，显示默认提示文字
    hideSmalltitle() {
      if (this.mobileName === '') {
        this.placeholder = '请输入手机号' //input默认提示字
      }
      this.isFocus = false
    },
    //验证用户是否存在  true是老用户，fasle是新用户
    async CheckAccountExsist(data) {
      try {
        const res = await this.$api.user.CheckAccountExsist({
          mobile: data
        })
        console.log('验证用户是否存在', res)
        this.olduser = res.data
        this.isAgree = res.data
      } catch (e) {}
    },
    //下一步
    nextStep() {
      // 判断是否勾选协议
      if (!this.isAgree) {
        this.showPopup = true
      } else {
        if (this.pasworcontrol) { //密码登录
          this.passwdlogn()
        } else { //跳转验证码登录
          var isMobile = true //true、手机号+验证码模式登入 fasle、账号+密码模式登入）
          if (this.passwordSMSLogin === '密码登录') {
            isMobile = true
          } else {
            isMobile = false
          }
          uni.navigateTo({
            url: '/pages_logins/enterCode/enterCode?mobileName=' + this.mobileName + '&isMobile=' + isMobile +
              '&invitationCode=' + this.invitationCode + '&olduser=' + this.olduser
          })
        }
      }
    },
    // 密码登录
    async passwdlogn() {
      const md5Pwd = this.md5(this.Password)
      try {
        const res = await this.$api.user.ClientLogin({
          mobile: this.mobileName, //用户名
          loginCode: md5Pwd, //	验证码/密码
          inviteCode: this.invitationCode, //邀请码
          imei: this.$store.state.imei, //IMEI
          LoginType: 1, //手机号密码登录传1
          login_Platform: this.platform, //设备平台信息-仅注册需要
        })
        if (res.code === 200) {
          this.loginSuccess(res.data) //保存
          uni.setStorage({
            key: 'launchFlag',
            data: true,
          })
          if (res.data.isNew) {
            uni.reLaunch({
              url: '/pages_logins/passwordLogin/passwordLogin?type=' + res.data.isNew
            })
          } else {
            // console.log('密码登录')

            this.$commen.loginSuccess()
            // uni.switchTab({
            //   url: '/pages/index/index'
            // })
          }
        } else {
          this.Password = ''
        }
      } catch (err) {
        console.log('捕获错误', err)
      }
    },

    //保存登录信息
    loginSuccess(param) {
      // 登录信息-vuex
      this.$store.commit('setModel', param)

      //token存储-缓存
      uni.setStorageSync('token', param.token)
      //用户信息-缓存
      uni.setStorageSync('Ztc_C_USER_INFO', param)
    },
    //勾选免责
    Agree() {
      this.isAgree = !(this.isAgree)
    },
    //历史号码点击
    selHistory(data) {
      var phones = data.replace(/\s+/g, '')
      this.mobileName = phones
      if (phones.length > 7) {
        this.namePhone =
          phones.slice(0, 3) +
          ' ' +
          phones.slice(3, 7) +
          ' ' +
          phones.slice(7)
      } else if (phones.length > 3) {
        this.namePhone = phones.slice(0, 3) + ' ' + phones.slice(3)
      } else {
        this.namePhone = phones
      }
      this.CheckAccountExsist(data)
      setTimeout(() => {
        this.isFocus = false
        this.nextStepstat = true //下一步点亮
      }, 200)

      this.invitationCode = ''
      this.olduser = false

    },
    //同意免责
    agreepopup(type) { //type 0不同意 1同意
      if (type === 0) {
        this.isAgree = false
        this.showPopup = false //关闭免责弹框
      } else {
        if (this.pasworcontrol) { //密码登录
          // this.passwdlogn()
          this.isAgree = true
          this.showPopup = false //关闭免责弹框
          this.nextStep()
        } else {
          // 点击同意跳到输入验证码的页面
          var isMobile = true //true、手机号+验证码模式登入 fasle、账号+密码模式登入）
          uni.navigateTo({
            url: '/pages_logins/enterCode/enterCode?mobileName=' + this.mobileName + '&isMobile=' + isMobile +
              '&invitationCode=' + this.invitationCode
          })
          this.showPopup = false //关闭免责弹框
        }
      }
    },
    //跳转协议
    gouserAgreementPage(type) {
      if (type === 0) {
        uni.navigateTo({
          // url: '/pages_logins/userAgreementPopup/userAgreementPopup'
          url: '/pages_logins/agreement/agreement'
        })
      } else {
        uni.navigateTo({
          url: '/pages_logins/agPrivacy/agPrivacy'
        })
      }

    },

    //
    async verifyMobile(data) {
      try {
        const res = await this.$api.user.GetAccountsByIMEI({
          imei: data,
          // imei: '861751030102251,861751030102244',
        })
        if (res.data.length > 0) {
          this.historyInfo = res.data //赋值历史手机号
          if (res.data.length === 1) {
            this.quickUser = res.data[0]
            this.mobileName = this.mobileName ? this.mobileName : res.data[0].mobile,
            this.CheckAccountExsist(this.mobileName)
            this.showClearIcon = true //显示小叉叉
            this.placeholder = '请输入手机号'
            this.olduser = false
          } else if (res.data.length > 1) {
            this.olduser = false
          }
          this.nextStepstat = true
        }
      } catch (e) {}
    },

    getUserCompany() {
      const _this = this
      this.$api.user.getUserCompany().then(res => {
        if (res.data.name) {
          _this.$store.commit('user/setCompanyInfo', {
            name: res.data.name,
            isJoinCompany: !res.data.isNew
          })
          uni.navigateTo({
            url: '/pages_login/authenticationPersonal/authenticationPersonal?companyName=' + res.data.name
          })
        } else {
          uni.navigateTo({
            url: '/pages_login/register/register'
          })
        }
      })
    },

    //获取用户信息
    async getUserInfo() {
      try {
        const res = await this.$api.user.getUserInfo()
        uni.setStorageSync('userInfoDetail', res.data)
        this.$store.commit('setUserInfoDetail', res.data)
      } catch (e) {
        //TODO handle the exception
      }
    },
    //验证码密码登录切换
    passSMSlclick() {
      if (this.passwordSMSLogin === '密码登录') {
        if (this.mobileName.length !== 11) {
          uni.showToast({
            title: '请输入手机号码',
            icon: 'none'
          })
          return false
        } else {
          this.passwordSMSLogin = '验证码登录'
          this.pasworcontrol = true //密码登录
          // this.invitationCode = ''
          this.showpasswordPlaceholder = false
          this.showPasswordClearIcon = false
          this.nextStepstat = false
          this.passwordPlaceholder = '请输入密码' //input默认提示
        }
      } else {
        this.passwordSMSLogin = '密码登录'
        this.pasworcontrol = false //密码登录
        this.Password = ''
        this.yqsuccess = false
        this.yqfail = false
        //手机号不为空下一步点亮
        if (this.mobileName !== '') {
          this.nextStepstat = true
        }
      }
    },

    //切换密码的显示隐藏
    changePassword() {
      if (this.eye === 'eye-off') {
        this.eye = 'eye-fill'
      } else {
        this.eye = 'eye-off'
      }
      this.showPassword = !this.showPassword
    },

    //当input框获取焦点的时候，显示小标题，隐藏默认提示文字
    toggleSmalltitle(isshow) { //type 0 企业名称 1请输入密码  isshow 0获取焦点 1失去焦点
      if (isshow === 0) { // 请输入密码获取焦点
        this.passwordPlaceholder = ''
        this.showpasswordPlaceholder = true
      } else { // 请输入密码失去焦点
        if (this.Password === '') {
          this.passwordPlaceholder = '请输入密码' //input默认提示
          this.showpasswordPlaceholder = false

        } else {
          this.showpasswordPlaceholder = true
        }
      }
    },
    //input后面的小叉叉
    clearIcon() {
      this.Password = ''
      this.showPasswordClearIcon = false
      this.passwordPlaceholder = '请输入密码' //input默认提示
      this.showpasswordPlaceholder = false
      this.isDisabled = true //提交按钮灰掉
    },

    //实时监测验证码是否输入完毕
    changeInput(e) {
      this.Password = e //input输入的内容
      if (e.length > 0) {
        this.showpasswordPlaceholder = true //提示
        if (e.length >= 6 && e.length <= 20) { //显示高亮下一步
          this.nextStepstat = true
        } else {
          this.nextStepstat = false
          if (e.length > 20) {
            uni.showToast({
              title: '您输入的密码超过20位',
              duration: 2000,
              icon: 'none'
            })
          }
        }

      } else {
        this.showPasswordClearIcon = false //小叉叉
      }
    },
    //实时监控 请输入密码input输入的值
    clearInputpassword(event) {
      this.Password = event.detail.value //input输入的内容
      if (event.detail.value.length > 0) {
        this.showPasswordClearIcon = true //小叉叉
        if (event.detail.value.length >= 6 && event.detail.value.length <= 20) { //显示高亮下一步
          this.nextStepstat = true
        } else {
          this.nextStepstat = false
          if (event.detail.value.length > 20) {
            uni.showToast({
              title: '您输入的密码超过20位',
              duration: 2000,
              icon: 'none'
            })
          }
        }

      } else {
        this.showPasswordClearIcon = false //小叉叉
      }
    },

    weixinClick() {
      // 1.用openid，判断是新用户 还是老用户（老用户判断token是否有效）
      // 2.新用户直接调取微信token ,跳微信登录页面，输入手机号，验证码，反予后台，后台反登录信息
      // 3.老用户点击微信获取token有效,后台反登录信息, 直接进入首页
      // 4.老用户token无效调取微信重新获取token，后台反登录信息,直接进入首页
      //最新打开小程序使用
      this.xcxWeixin()
      // this.testfn()
      // 原本微信登录
      // this.weixin()

    },
    //测试方法
    testfn(){
      //#ifdef APP-PLUS
      // if(this.sweixin){
      //   this.sweixin.launchMiniProgram({
      //     path: '/pages_logins/appLogin/login',
      //     type: 2,//可取值： 0-正式版； 1-测试版； 2-体验版。 默认值为0。
      //     id: 'gh_fe19d042f1b9'
      //   })
      // }else{
      //   plus.nativeUI.alert('请下载微信后再使用')
      // }
      //#endif
    },
    //直接跳转到小程序，关闭当前进程
    xcxWeixin() {
      //#ifdef APP-PLUS
      if (this.sweixin) {
        this.sweixin.launchMiniProgram({
          path: '/pages_logins/login/login',
          type: 0, //可取值： 0-正式版； 1-测试版； 2-体验版。 默认值为0。
          id: 'gh_fe19d042f1b9'
        })
        //关闭进程
        setTimeout(() => {
          if (plus.os.name.toLowerCase() === 'android') {
            plus.runtime.quit()
          } else {
            const threadClass = plus.ios.importClass('NSThread')
            const mainThread = plus.ios.invoke(threadClass, 'mainThread')
            plus.ios.invoke(mainThread, 'exit')
          }
        }, 300)
      } else {
        plus.nativeUI.alert('请下载微信后再使用')
      }
      //#endif
    },
    zhifubaoClick() {

    },
    pingguoClick() {

    },
    //微信登录token用户信息
    async GetUserByWCTokenResponse(type) {
      console.log('111', type.authResult.openid)
      console.log('222', type.authResult.access_token)
      try {
        const res = await this.$api.user.GetUserByWCTokenResponse({
          token: type.authResult.access_token,
          openId: type.authResult.openid
        })
        console.log(res)
        if (res.data.existWeChatAccount) {
          // true为老用户跳入首页，false为新用户跳微信登录页
          this.loginSuccess(res.data) //保存
          uni.setStorage({
            key: 'launchFlag',
            data: true,
          })
          uni.switchTab({
            url: '/pages/index/index'
          })
        } else {
          uni.navigateTo({
            url: '/pages_logins/loginWeixin/loginWeixin?weixinList=' + encodeURIComponent(JSON.stringify(
              type))
          })
        }
      } catch (e) {}
    },
    weixin() {
      // 第一授权获取用户信息 ===》按钮触发
      let _self = this
      // 1.获取用户的信息
      uni.login({
        provider: 'weixin',
        success: infoRes => {
          console.log(123, infoRes)
          uni.showToast({
            title: '获取微信信息成功',
            icon: 'none'
          })
          // 2.后台接收接口
          this.GetUserByWCTokenResponse(infoRes)
        },
        fail: e => {
          this.weixnumber++
          if (this.weixnumber <= 2) {
            this.weixin()
            console.log('获取失败执行次数', this.weixnumber)
          }
          console.log('获取失败返回', e)
          uni.showToast({
            title: '获取失败,请检查微信是否是登录状态',
            icon: 'none'
          })
        }
      })
    },
    //提交自助洗车会员卡订单
    async AddSelfServiceCarWashDiscountOrder(types) {
      try {
        let data = {
          self_Service_Car_Wash_Card_Id: this.purchaseinformation.self_Service_Car_Wash_Card_Id,
          purchase_Channel: 3, // 购买途径 1：平台 2：线下  3：推广（从落地页跳转的）
          self_Service_Car_Wash_Station_Id: this.purchaseinformation.self_Service_Car_Wash_Station_Id, //凤英传的商户端的门店ID
        }
        const res = await this.$api.selfServiceCarWash.AddSelfServiceCarWashDiscountOrder(data)
        uni.hideLoading()
        let carmoney = this.purchaseinformation.price
        if (res.code === 200) {
          uni.navigateTo({
            url: `/pages_commodity/newPay/newPay?orderNo=${res.data}&type=selfServiceCarWashCoupon&price=${carmoney}&machineId=${''}`
            // url: `/pages_commodity/payment/payment?orderNo=${res.data}&type=selfServiceCarWashCoupon&price=${carmoney}&machineId=${''}`
          })
        }
      } catch (e) {
        console.log(e)
      }
    },
  },
}